<?php
/*
 +----------------------------------------------------------------------
 + Title        : IdCardCheck 控制器
 + Author       : Randy_chen
 + Version      : V1.0.0.1
 + Initial-Time : 2021/3/9 23:45
 + Last-time    : 2021/3/9 23:45+ chen2
 + Desc         : IdCardCheck
 +----------------------------------------------------------------------
*/


namespace aliyun;

use app\api\exception\ApiException;
use think\Log;
use utils\ExtendHttp;

/**
 * 身份验证
 * Class IdCardCheck
 *
 * @package aliyun
 */
class IdCardCheck
{
    const URL = "https://idcardcert.market.alicloudapi.com/idCardCert";

    public static function check($idcard, $username)
    {
        $options['headers'][] = "Authorization:APPCODE " . config('idCardCert.AppCode');
        $params['idCard'] = $idcard;
        $params['name'] = $username;
        $url = self::URL;
        $res = ExtendHttp::get($url, $params, $options);
        $result = json_decode($res, true);
        if (!$result) {
            error_abort('身份证校验未通过~');
        }
        if ($result['status'] !== '01') {
            error_abort($result['msg']);
        }
        return $result;
    }

}